{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "234107eb-1d76-4f18-8061-415709516be4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "5d9c9fc8-e105-4eb9-b9de-74046a43b4de",
   "metadata": {},
   "outputs": [],
   "source": [
    "blockSize = 2\n",
    "ksize = 3\n",
    "k = 0.04"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3fcfe29e-bd21-4dd5-bad6-05902d6062d9",
   "metadata": {},
   "outputs": [],
   "source": [
    "img = cv2.imread('test1.png')\n",
    "\n",
    "# 显示窗口之后，读取按键之后关闭\n",
    "cv2.imshow('original', img)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b7a8f8fe-697e-4bed-a035-850b299fc8bd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 灰度化\n",
    "gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "20b177b0-a6b3-4e1e-8d2e-81e92fa39456",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Harris角点检测\n",
    "# blockSize 检测窗口大小\n",
    "# ksize Sobel的卷积核\n",
    "# k 权重系数，经验值，一般取值0.02~0.04之间\n",
    "dst = cv2.cornerHarris(gray, blockSize, ksize, k)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "28df11df-3b65-4283-a573-58c94fb15fb0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Harris角点展示\n",
    "img[dst>0.01*dst.max()] = [0,0,255]\n",
    "\n",
    "# 显示窗口之后，读取按键之后关闭\n",
    "cv2.imshow('harris', img)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "94668a09-95e2-478b-8e44-4591ad2c3481",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4.9.0\n"
     ]
    }
   ],
   "source": [
    "print(cv2.__version__)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
